package android.slc.extras.system.domain

import android.slc.app.startup.TaskConstant
import android.slc.app.startup.TaskUtils
import android.slc.appbase.ui.vd.BaseAppVmBox
import com.blankj.utilcode.util.ThreadUtils
import com.effective.android.anchors.AnchorsManager
import com.effective.android.anchors.task.Task
import com.kunminx.architecture.ui.callback.ProtectedUnPeekLiveData
import com.kunminx.architecture.ui.callback.UnPeekLiveData

class StartupUiTaskVmBox : BaseAppVmBox() {

    private val uiTaskEndVd = UnPeekLiveData<Boolean>()

    fun start() {
        if (uiTaskEndVd.isInitialized) {
            return
        }
        ThreadUtils.runOnUiThreadDelayed({
            AnchorsManager.getInstance()
                .debuggable(true)
                .start(
                    TaskUtils.getDelayTaskBuilder().add(object : Task("startupUiTask") {
                        override fun run(name: String) {
                            uiTaskEndVd.value = true
                        }
                    }).dependOn(TaskConstant.TASK_THIRD_PART, TaskConstant.TASK_SLC).build()
                )
        }, 32)
    }

    fun getUiTaskEndVd(): ProtectedUnPeekLiveData<Boolean> {
        return uiTaskEndVd
    }

    fun isTaskEnd(): Boolean {
        return uiTaskEndVd.isInitialized
    }
}